
import { _decorator, Component, Node, EditBox } from 'cc';
const { ccclass, property } = _decorator;
import dwebAjax from "./dwebXHR"
/**
 * Predefined variables
 * Name = register
 * DateTime = Thu Mar 03 2022 23:51:10 GMT+0800 (中国标准时间)
 * Author = zxq6635624
 * FileBasename = register.ts
 * FileBasenameNoExtension = register
 * URL = db://assets/script/register.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */
 
@ccclass('register')
export class register extends Component {
    // [1]
    // dummy = '';

    // [2]
    // @property
    // serializableDummy = 0;
    username = null;
    password = null;
    password2 = null;

    start () {
        // [3]
      this.username = this.node.getChildByName("UserName")
      this.password = this.node.getChildByName("PassWord")
      this.password2 = this.node.getChildByName("PassWord2")
    }

    toRegister(){
      let username = this.username.getComponent(EditBox).string
      let password = this.password.getComponent(EditBox).string
      let password2 = this.password2.getComponent(EditBox).string
      let data = {
        username: username,
        password: password,
        password2: password2
      }
      dwebAjax.sendAjax("/api-json/register/",data,"POST",(res)=>{
        console.log(res)
        if (res == "same pwd") {
          alert("两次密码不一致");
          return
        }
        if (res == "pwd or username err") {
          alert("用户名5位 密码8位");
          return
        }
        if (res == "user exist") {
          alert("用户名已经注册");
          return
        }
        if (res == "okk") {
          alert("注册成功 返回登录吧");
          return
        }
      })
    }


    changeLogin(){
      this.node.active = false
      this.node.getParent().getChildByName('LoginBox').active = true
    }

    // update (deltaTime: number) {
    //     // [4]
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
